package com.jxw.launcher;

import android.content.Context;
import android.os.Process;
import java.io.UnsupportedEncodingException;
import java.lang.Thread;
import org.json.JSONException;

/* loaded from: classes.dex */
public class CrashHandler implements Thread.UncaughtExceptionHandler {
    private static CrashHandler INSTANCE;
    private Context mContext;
    private Thread.UncaughtExceptionHandler mDefaultHandler;

    private CrashHandler() {
    }

    public static CrashHandler getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new CrashHandler();
        }
        return INSTANCE;
    }

    public void init(Context context) {
        this.mContext = context;
        this.mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
        Thread.setDefaultUncaughtExceptionHandler(this);
    }

    @Override // java.lang.Thread.UncaughtExceptionHandler
    public void uncaughtException(Thread thread, Throwable th) {
        try {
            CrashLogUtils.saveLogToFile(this.mContext, th);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
        this.mDefaultHandler.uncaughtException(thread, th);
    }

    /* JADX WARN: Type inference failed for: r0v1, types: [com.jxw.launcher.CrashHandler$1] */
    public boolean handleException(final Throwable th) {
        if (th == null || this.mContext == null) {
            return false;
        }
        new Thread() { // from class: com.jxw.launcher.CrashHandler.1
            @Override // java.lang.Thread, java.lang.Runnable
            public void run() {
                th.printStackTrace();
                try {
                    CrashLogUtils.saveLogToFile(CrashHandler.this.mContext, th);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                Process.killProcess(Process.myPid());
                System.exit(1);
            }
        }.start();
        return true;
    }
}
